package com.hospital.doctor.doctory.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hospital.doctor.doctory.dao.DepartmentCtMapper;
import com.hospital.doctor.doctory.dao.QueueMapper;
import com.hospital.doctor.doctory.entity.DepartmentCt;
import com.hospital.doctor.doctory.service.DepartmentCtService;
import com.hospital.xiaochengxiu.yan.dao.DepartmentQueueMapper;
import com.hospital.xiaochengxiu.yan.entity.DepartmentQueue;
import com.hospital.xiaochengxiu.yan.service.DepartmentQueueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author ：ysb
 * @ClassName ：DepartmentCtServiceImpl
 * @Package ：com.hospital.doctor.doctory.service.impl
 * @Description:
 * @Date:2021/11/4 9:28
 */
@Service
public class DepartmentCtServiceImpl implements DepartmentCtService {

    @Autowired
    private DepartmentCtMapper departmentCtMapper;
    @Autowired
    private DepartmentQueueMapper departmentQueueMapper;

    /**
     * 根据诊疗号查询过往检查记录
     * @param CdiagnoseNO
     * @return
     */
    @Override
    public List<DepartmentCt> selectInspectionRecord(Integer CdiagnoseNO) {
        return departmentCtMapper.selectInspectionRecord(CdiagnoseNO);
    }

    /**
     * 开具检查单
     * @param departmentQueue
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED)
    public String insertRecord(DepartmentQueue departmentQueue) {
        QueryWrapper<DepartmentQueue> queryWrapper=new QueryWrapper();
        queryWrapper
                .eq("userId",departmentQueue.getUserId())
                .in("state",0,1,2)
                .eq("userType",departmentQueue.getUserType());
        Integer integer = departmentQueueMapper.selectCount(queryWrapper);
        if(integer==0){
             int insert = departmentQueueMapper.insert(departmentQueue);
            return "成功";
        }
        return "已开具同样的检查";
    }
}
